// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * CommandLine.h
 *
 *  Created on: Jan 3, 2010
 *      Author: dhovemey
 */

#ifndef COMMANDLINE_H_
#define COMMANDLINE_H_

#include <map>
#include <string>
#include "util/Exception.h"

class CommandLineException : public Exception {
private:
	CommandLineException& operator=(const CommandLineException &);

public:
	CommandLineException(const std::wstring &msg);
	CommandLineException(const CommandLineException &other);
	virtual ~CommandLineException();
};

class CommandLine {
private:
	typedef std::map<std::string, bool> OptionMap;
	OptionMap m_optionMap;
	std::string m_progName;

	CommandLine(const CommandLine &);
	CommandLine& operator=(const CommandLine &);

public:
	CommandLine();
	CommandLine(const char *format);
	~CommandLine();

	void addSwitch(const std::string &opt) { m_optionMap[opt] = false; }
	void addOption(const std::string &opt) { m_optionMap[opt] = true; }

	virtual void parse(int &argc, char **&argv);
	std::string getProgName() const { return m_progName; }

	virtual void handleSwitch(const std::string &name) = 0;
	virtual void handleOption(const std::string &name, const std::string &arg) = 0;
};

#endif /* COMMANDLINE_H_ */
